package com.woniuxy.carlife.carlifeorderweb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.carlifecommonsweb.util.CopyUtil;
import com.woniuxy.carlife.carlifeorderweb.domain.Order;
import com.woniuxy.carlife.carlifeorderweb.domain.ProductDetail;
import com.woniuxy.carlife.carlifeorderweb.response.OrderResp;
import com.woniuxy.carlife.carlifeorderweb.service.OrderService;
import com.woniuxy.carlife.carlifeorderweb.service.ProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
*@ClassName:OrderController
*@Description:服务订单、商品订单下单、查询及支付接口
*@author qk
*@date 2021/4/7 16:04
**/
@RestController
@RequestMapping("//order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private ProductDetailService productDetailService;
    /*
     * 功能描述〈服务、商品订单生成〉
     * @author:qk
     * @param:买家bid;买家sid
     * @return:
  * @Date 2021/4/7 16:06
     * @throws //
     */
    @PutMapping("/ordinary/addOrder")
    public Result addOrder(int bid,int sid){
        return new Result();
    }
    /*
     * 功能描述〈商品、服务订单支付〉
     * @author:qk
     * @param:
     * @return:
     * @Date 2021/4/7 16:11
     * @throws //
     */
    @GetMapping("/ordinary/payForOrder")
    public Result payForOrder(){
        return new Result();
    }
    /*
     * 功能描述〈商品订单查询〉
     * @author:qk
     * @param:订单id
     * @return:订单信息及详情
     * @Date 2021/4/7 16:15
     * @throws //
     */
    @GetMapping("/ordinary/getOrderOfProduct")
    public Result getOrder(String oid){
        Order byId = orderService.getById(oid);
        OrderResp orderResp = new OrderResp();
        orderResp.setUserid(byId.getBid());
        orderResp.setPayment(byId.getOStatus());
        orderResp.setPrice(byId.getFinalPrice());
        orderResp.setTakeGoods(byId.getTakeGoods());
        QueryWrapper<ProductDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("oid",oid);
        ProductDetail detail = productDetailService.getOne(queryWrapper);
        orderResp.setServiceImg(detail.getProuductImg());
        orderResp.setShopname(detail.getSellerName());
        return new Result(true, StatusCode.OK,"查询成功",orderResp);
    }
    /*
     * 功能描述〈商品、服务订单删除〉
     * @author:qk
     * @param:订单id
     * @return:删除结果
     * @Date 2021/4/7 16:15
     * @throws //
     */
    @GetMapping("/ordinary/deleteOrder")
    public Result deleteOrder(String oid){
        boolean b = orderService.removeById(oid);
        if(b){
            return new Result(true, StatusCode.OK,"删除成功");
        }
        return new Result(false, StatusCode.ERROR,"删除失败");
    }
}

